<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<link rel="stylesheet" href="../../res/layui/css/layui.css" media="all">
<link rel="stylesheet"
	href="../../res/zTree_v3-master/css/metroStyle/metroGreen.css"
	type="text/css">
<script src="../../res/js/jquery-3.4.1.min.js" type="text/javascript"
	charset="utf-8"></script>
<script type="text/javascript" src="../../res/layui/layui.js"></script>
<script type="text/javascript" src="../../res/module/common.js"></script>
<script type="text/javascript" src="../../res/module/treeSelect/treeSelect.js"></script>
<title>操作界面</title>
</head>
<body>
	<div style="margin-top: 10px; padding-right: 27px;">
		<form class="layui-form" id="idform" action="">
			<input id="rivId" type="hidden" name="rivId" lay-verify="title"
				   autocomplete="off" class="layui-input" >
			<div class="layui-form-item">
				<label class="layui-form-label">对手名字</label>
				<div class="layui-input-block">
					<input id="rivName" type="text" name="rivName" lay-verify="required|title"
						autocomplete="off" placeholder="对手名字" class="layui-input">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">请选择性别</label>
				<div class="layui-input-block">
					<select name="rivSex" lay-verify="required" lay-search="">
			          <option value="男">男</option>
			          <option value="女">女</option>
			        </select>
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">缺点</label>
				<div class="layui-input-block">
					<input id="rivFailing" type="text" name="rivFailing" lay-verify="required|title"
						   autocomplete="off" placeholder="请输入" class="layui-input">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">技术风格</label>
				<div class="layui-input-block">
					<input name="rivTechnique" type="text" id="rivTechnique" placeholder="请输入"
						lay-filter="tree" class="layui-input" lay-verify="required|title">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">战术风格</label>
				<div class="layui-input-block">
					<input name="rivTactics" type="text" id="rivTactics" placeholder="请输入"
						   lay-filter="tree" class="layui-input" lay-verify="required|title">
				</div>
			</div>
			<div class="layui-form-item">
				<div class="layui-input-block">
					<button type="submit" class="layui-btn" lay-submit
						lay-filter="demo1">立即提交</button>
					<button type="reset" class="layui-btn layui-btn-primary">重置</button>
				</div>
			</div>
		</form>
	</div>
	<script>
		$(function(){
			//修改是出现的值
			var one = getQueryStringOne("rivId");
			if(one != ""){
				var url = "../../../atsRival/updateQuery";
				var data ={rid:getQueryStringOne("rivId")};
				$.post(url,data,function(obj){
					$("#rivId").val(obj.data.rivId);
					$("#rivName").val(obj.data.rivName);
					$("#rivSex").val(obj.data.rivSex);
					$("#rivFailing").val(obj.data.rivFailing);
					$("#rivTechnique").val(obj.data.rivTechnique);
					$("#rivTactics").val(obj.data.rivTactics);
					$.each(obj.data.list,function(index,item){
						$("#"+item.rivId+"").prop("checked","checked");
					})

				},'json')
			}
		})
	</script>
	<script>
		//Demo
		var form = null;

		layui.use('form', function() {
			 var form = layui.form;
			//监听提交
			form.on('submit(demo1)', function(data) {
				//layer.msg(JSON.stringify(data.field));//弹出选择的信息
				var form = new FormData(document.getElementById("idform"));
				$.ajax({
					url : "../../../atsRival/insertOrUpdate",
					type : "post",
					data : form,
					dataType : "json",
					processData : false,
					contentType : false,
					success : function(obj) {
						if (obj.num == 1) {
							//弹出需求
							layer.msg(obj.msg, {
								icon : 1,
								time : 1000
							//一秒关闭 如果不配置是3秒 
							}, function() {
								//关闭 层
								var index = parent.layer
										.getFrameIndex(window.name);//得到iframe 层的索引
								parent.layer.close(index);//关闭改层
								//关闭父级页面的表格
								parent.layui.table.reload('testReload');
							});
						} else {
							layer.msg(obj.msg);
						}
					},
					error : function(e) {

					}
				});
				return false;
			});
		});
		//得到地址栏上的参数  可以 是中文 
		function getQueryStringOne(key) {
			var reg = new RegExp("(^|&)" + key + "=([^&]*)(&|$)");
			var r = window.location.search.substr(1).match(reg);
			if (r != null)
				return decodeURI(r[2]);
			return null;
		}
	</script>
</body>
</html>